package ooad.gof.observer;
import java.util.ArrayList;
import java.util.List;

public abstract class Subject {
	private boolean isChanged = false;
	List<AbstractObserver>  list = new ArrayList<AbstractObserver>();
	public void attach(AbstractObserver observer) {
		list.add(observer);		
	}
	public void detach(AbstractObserver observer) {
		list.remove(observer);		
	}
	public void detachAll() {
		list.clear();		
	}
	public void notifyObserver(Object arg) {
		if (isChanged){
			for(AbstractObserver observer : list){
				observer.update(this, arg);
			}
		}
		
	}
	protected synchronized void setChanged() {
		isChanged = true;
	}
}
